home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
DELTASOU
/
DELTASOU.C
< prev
Wrap
C/C++ Source or Header
|
1989-09-16
|
3KB
|
152 lines
/*
>> DeltaSound.c
>> Copyright ⌐1989, Juri Munkki
>>
>> Takes any file and modifies the data fork
>> so that sound files compress to smaller
>> files. Forward process is called "differentiate"
>> and backward "integrate".
*/
SFReply reply;
int direction;
/*
>> All the actual work is done inside this
>> filter procedure. If the user opens a file,
>> we open a working directory, and then
>> process the file according to the direction
>> flag. 0 is forward, anything else is back.
*/
pascal int FilterProc(item,dialog)
int item;
DialogPtr dialog;
{
int refnum;
char buffer[16384];
WDPBRec dir;
register char *from,*to,old,new;
register long looper;
long mark,len;
DialogPtr message;
int theerr;
if(item==getOpen) /* Is Open button hit? */
{ /* Tell the user that work is being done! */
SetCursor(*GetCursor(watchCursor));
message=GetNewDialog(1001,0,-1);
DrawDialog(message);
dir.ioCompletion=0; /* See relevant technotes and */
dir.ioNamePtr=0; /* Inside Macintosh chapters */
dir.ioVRefNum=-SFSaveDisk; /* for information on why and */
dir.ioWDProcID='ERIK'; /* how we open a working */
dir.ioWDDirID=CurDirStore; /* directory. */
theerr=PBOpenWD(&dir,0);
reply.vRefNum=dir.ioVRefNum;
FSOpen(reply.fName,reply.vRefNum,&refnum);
old=128; /* First value can be anything */
do
{ len=16384;
GetFPos(refnum,&mark);
FSRead(refnum,&len,buffer);
if(len>0)
{ from=to=buffer;
if(direction)
{ asm {
move.w #16383,looper
@intg move.b (from)+,new
sub.b new,old
move.b old,(to)+
dbra looper,@intg
}
}
else
{ asm {
move.w #16383,looper
@dif move.b (from)+,new
sub.b new,old
move.b old,(to)+
move.b new,old
dbra looper,@dif
}
}
SetFPos(refnum,fsFromStart,mark);
FSWrite(refnum,&len,buffer);
}
} while(len==16384);
FSClose(refnum);
FlushVol(0L,reply.vRefNum);
item=100;
DisposDialog(message);
SetCursor(&arrow);
}
return item;
}
/*
>> Some users like to use the keyboard for quitting
>> and buttons. This simple procedure defines some
>> shortcuts. I would not write anything like this
>> into a real application. Real applications use
>> resources so that the user can edit the shortcuts.
*/
pascal int keyfilter(theDialog,theEvent,itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
int *itemHit;
{
if(theEvent->what==keyDown && (theEvent->modifiers & cmdKey))
{ switch((char)theEvent->message)
{ case 'Q':
case 'q':
case '.':
*itemHit=2;
break;
case 'D':
case 'd':
*itemHit=3;
break;
case 'I':
case 'i':
*itemHit=4;
break;
default:
*itemHit=0;
}
return -1;
}
return 0;
}
void main()
{
DialogPtr thedia;
int thehit;
int zerostring=0;
InitGraf(&thePort); InitCursor();
InitFonts(); InitWindows();
InitMenus(); TEInit();
InitDialogs(0L);
thedia=GetNewDialog(1000,0,-1);
do
{ ModalDialog(keyfilter,&thehit);
switch(thehit)
{ case 3:
direction=0;
SFGetFile(0x00400048L,&zerostring,0L,-1,0L,FilterProc,&reply);
break;
case 4:
direction=1;
SFGetFile(0x00400048L,&zerostring,0L,-1,0L,FilterProc,&reply);
break;
}
} while(thehit!=2);
}